<template>
  <div>
    地址：<el-input placeholder="请输入内容" v-model="dizhi" clearable style="width: 200px;">
  </el-input>

    状态：<el-select v-model="value" placeholder="请选择">
      <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value">
      </el-option>
    </el-select>
    <el-button type="primary" icon="el-icon-search" @click="verification">查询</el-button>
    <div>
      <!--表格-->
      <el-table
        :data="tableData"
        border
        style="width: 100%">
        <el-table-column
          type="index"
          :index="indexMethod"
          width="50">
        </el-table-column>
        <el-table-column
          prop="vmid"
          label="售货机id"
          width="120">
        </el-table-column>
        <el-table-column
          prop="vmSite"
          label="售货机地址"
          width="300">
        </el-table-column>
        <el-table-column
          prop="vmState"
          label="售货机状态"
          width="100">
        </el-table-column>
        <el-table-column
          prop="vmCapital"
          label="售货机盈利"
          width="180">
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)">禁用
            </el-button>
            <el-button
              size="mini"
              type="success"
              @click="handleEdit(scope.$index, scope.row)">启用
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page=page
        :page-sizes="[5, 10, 15, 20]"
        :page-size=size
        layout="total, sizes, prev, pager, next, jumper"
        :total=total>
      </el-pagination>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'VendingMachine',
    mounted() {//默认第一次加载
      initTable(this)
    },
    data () {
      return {
        pickerOptions: {
          disabledDate (time) {
            return time.getTime() > Date.now()
          }
        },
        tableData: [],
        total: 0,
        page: 1,
        size: 5,
        subForm:{
          startTime:'',
          overTime:''
        },
        options: [{
          value: '禁用',
          label: '禁用'
        }, {
          value: '启用',
          label: '启用'
        }],
        value: '',
        dizhi: ''
      }
    },
    methods: {

      //以下是表格部分的方法
      indexMethod(index) {
        return index + 1
      },
      handleSizeChange(val) {
        this.size = val
        initTable(this)
        console.log(`每页 ${val} 条`)
      },
      handleCurrentChange(val) {
        this.page = val
        initTable(this)
        console.log(`当前页: ${val}`)
      },
      verification:function () {
          this.$axios.post("vmcx", {
              page: this.page,
              size: this.size,
              vmState: this.value,
              vmSite: this.dizhi
          }).then(resp => {
            if (resp) {
              $this.tableData = resp.data.tbVmiList
              $this.total = resp.data.count
            }
          })
        }
      },
  }
  function initTable($this) {
    $this.$axios.post("VM", {
      page: $this.page,
      size: $this.size
    }).then(resp => {
      if (resp) {
        $this.tableData = resp.data.vmiList
        $this.total = resp.data.count
      }
    })
  }
</script>

<style scoped>

</style>
